<template>
  <div class="admin-home">
    <div class="welcome-card">
      <h2>欢迎，{{ userName }}（管理员）！</h2>
      <p>您可以发布任务、查看日志、统计报表，管理全局任务。</p>
    </div>
    <div class="stats-row">
      <div class="stat-card">
        <div class="stat-num">{{ stats.today }}</div>
        <div class="stat-label">今日发布</div>
      </div>
      <div class="stat-card">
        <div class="stat-num">{{ stats.doing }}</div>
        <div class="stat-label">进行中</div>
      </div>
      <div class="stat-card">
        <div class="stat-num">{{ stats.done }}</div>
        <div class="stat-label">已完成</div>
      </div>
      <div class="stat-card">
        <div class="stat-num">{{ stats.overdue }}</div>
        <div class="stat-label">逾期</div>
      </div>
      <div class="stat-card">
        <div class="stat-num">{{ stats.total }}</div>
        <div class="stat-label">总任务数</div>
      </div>
    </div>
    <div class="quick-row">
      <el-button type="primary" @click="goToPublish">发布新任务</el-button>
      <el-button @click="goToLog">查看任务日志</el-button>
      <el-button @click="goToReport">任务统计报表</el-button>
    </div>
    <div class="main-row">
      <!-- 最近发布任务表格已删除 -->
    </div>
  </div>
</template>

<script>
import request from '@/utils/request'
export default {
  name: 'AdminHome',
  data() {
    return {
      userName: this.$store.state.user.name || '管理员',
      stats: { today: 0, doing: 0, done: 0, overdue: 0, total: 0 }
    }
  },
  created() {
    this.loadStats();
  },
  methods: {
    loadStats() {
      request({
        url: '/emergency/task/stats',
        method: 'get'
      }).then(res => {
        if (res.code === 200 && res.data) {
          this.stats = res.data;
        }
      });
    },
    formatStatus(row) {
      const map = { 0: '待处理', 1: '进行中', 2: '已完成', 3: '逾期' };
      return map[row.status] || '未知';
    },
    goToPublish() {
      this.$router.push('/emergency/task/index');
    },
    goToLog() {
      this.$router.push('/emergency/log/index');
    },
    goToReport() {
      this.$router.push('/emergency/task/report');
    },
    goToUser() {
      this.$router.push('/system/user/index');
    },
    viewTask(row) {
      this.$router.push({ path: '/emergency/task/index', query: { id: row.id } });
    },
    editTask(row) {
      this.$router.push({ path: '/emergency/task/index', query: { id: row.id, edit: 1 } });
    }
  }
}
</script>

<style scoped>
.admin-home {
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 16px;
}
.welcome-card {
  background: #f0f9ff;
  border-radius: 12px;
  padding: 24px 32px;
  margin-bottom: 24px;
  box-shadow: 0 2px 8px rgba(33,147,176,0.06);
}
.stats-row {
  display: flex;
  gap: 24px;
  margin-bottom: 24px;
}
.stat-card {
  flex: 1;
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 1px 4px rgba(33,147,176,0.08);
  padding: 20px 0;
  text-align: center;
}
.stat-num {
  font-size: 2.2rem;
  color: #2193b0;
  font-weight: bold;
}
.stat-label {
  color: #888;
  margin-top: 8px;
}
.quick-row {
  margin-bottom: 24px;
  display: flex;
  gap: 16px;
}
.main-row {
  display: flex;
  gap: 24px;
}
.main-card {
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 1px 4px rgba(33,147,176,0.08);
  padding: 20px 24px 24px 24px;
  margin-bottom: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.notice-list {
  padding-left: 18px;
  color: #666;
  font-size: 15px;
}
</style> 